package com.example.mydefinedview1.ui

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View

/**
 *
 * @Author： LJH
 * @Time： 2022/6/29
 * @description：
 */
class HistogramView(context: Context, attr:AttributeSet?):View(context,attr) {
    private val paint = Paint()
    private val path = Path()

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
//        综合练习
//        练习内容：使用各种 Canvas.drawXXX() 方法画直方图
        paint.style = Paint.Style.STROKE
        paint.color = Color.WHITE
        paint.strokeWidth = 2F
        path.run {
            moveTo(100F,100F)
            lineTo(100F,400F)
            lineTo(600F,400F)
        }
        canvas?.drawPath(path,paint)
        paint.isAntiAlias = true
        paint.strokeWidth = 1F
        paint.textSize = 13F
        paint.letterSpacing = 0.08F
        canvas?.drawText("Integer",120F,420F,paint)
        canvas?.drawText("Float",190F,420F,paint)
        canvas?.drawText("Double",250F,420F,paint)
        canvas?.drawText("Byte",316F,420F,paint)
        canvas?.drawText("Long",376F,420F,paint)
        canvas?.drawText("Short",440F,420F,paint)
        canvas?.drawText("Boolean",500F,420F,paint)
        paint.style = Paint.Style.FILL
        paint.textSize = 24F
        paint.letterSpacing = 0.6F
        canvas?.drawText("直方图",280F,469F,paint)
        paint.color = Color.GREEN
        paint.style = Paint.Style.FILL
        canvas?.drawRect(180F,390F,230F,399F,paint)
        canvas?.drawRect(245F,390F,295F,399F,paint)
        canvas?.drawRect(305F,300F,355F,399F,paint)
        canvas?.drawRect(370F,100F,420F,399F,paint)
        canvas?.drawRect(435F,60F,485F,399F,paint)
        canvas?.drawRect(500F,320F,550F,399F,paint)

    }
}